package com.seeyon.apps.kk.util;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.csvreader.CsvReader;

public class CsvHandler {
	
	private static final Log log = LogFactory.getLog(CsvHandler.class);
	
	public static List<String[]> handler(String filePath) throws Exception {  
		
		List<String> legalEntities = Arrays.asList("LE_MRC_7055_3435","LE_MRC_7052_3435","LE_MRC_7051_3435","LE_MRC_7053_3455","LE_MRC_7076_3432");
		
        CsvReader reader = null;  
        List<String[]> dataList = new ArrayList<String[]>();  
        try {  
            char separator = 0;
			reader = new CsvReader(filePath, separator, Charset.forName("UTF-8"));  
            // 读取表头  加上这一句是不算表头数据从第二行开始取
            reader.readHeaders();  
            // 逐条读取记录，直至读完  
            while (reader.readRecord()) {
            	String[] data = reader.getRawRecord().split(",");
            	if(legalEntities.contains(data[146])){
            		dataList.add(data);
            	}
            }
            return dataList; 
        } catch (Exception e) {  
        	log.error("##强生客开: 读取CSV出错", e);  
            throw e;  
        } finally {  
            if (null != reader) {  
                reader.close();  
            }  

        } 

    }  
	
}
